package com.gopay.common.order.manager.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gopay.common.domain.cps.CpsBatchPayTask;
import com.gopay.common.domain.cps.CpsBatchTaskTargetRel;
import com.gopay.common.order.dao.CpsBatchPayTaskQueryDAO;
import com.gopay.common.order.dao.CpsBatchTaskTargetRelQueryDAO;
import com.gopay.common.order.manager.CpsBatchPayTaskQueryManager;

/**
 * 批量任务Manager实现类
 * 
 * @CpsBatchPayTaskQueryManagerImpl.java
 * @author liuxin
 * @2013-3-5 下午1:43:54 www.gopay.com.cn Inc.All rights reserved.
 */
@Service(value = "cpsBatchPayTaskQueryManager")
public class CpsBatchPayTaskQueryManagerImpl implements CpsBatchPayTaskQueryManager {

    @Resource(name = "cpsBatchPayTaskQueryDAO")
    private CpsBatchPayTaskQueryDAO cpsBatchPayTaskQueryDAO;

    @Resource(name = "cpsBatchTaskTargetRelQueryDAO")
    private CpsBatchTaskTargetRelQueryDAO cpsBatchTaskTargetRelQueryDAO;

    @Override
    public String getBatchNumByTargetId(String targetId) {
        CpsBatchTaskTargetRel targetRel = cpsBatchTaskTargetRelQueryDAO.getTargetRelByTargetId(targetId);
        if (targetRel == null) {
            return DEFAULT_BATCH_NUM;
        }
        CpsBatchPayTask payTask = cpsBatchPayTaskQueryDAO.find(CpsBatchPayTask.class,
                Long.valueOf(targetRel.getBatchTaskId()));
        return payTask != null ? payTask.getBatchNum() : DEFAULT_BATCH_NUM;
    }

}
